import { ApiCall } from "tsrpc";
import { ReqRank_look, ResRank_look } from "../../../shared/master/rank/PtlRank_look";
import { player } from "../../../model/fight/body/player";
import server_rank from "../../../server_rank";
import { template, Tpl_rankInfo } from "../../../shared/master/MsgAction";
import { rank_type, rank_typeName } from "../../../shared/interface";

export default async function (call: ApiCall<ReqRank_look, ResRank_look>) {
    call.succ({})
    let user = call.req._player as player;
    let data = await server_rank.c_http.callApi('Look', {
        type: call.req.type,
        uuid: user.uuid
    })
    let res = data.res;
    if (!res) {
        user.sendMsg(template.default, '排行榜查询失败');
        return;
    }
    let query_rank = res.query_rank
    let list = res.list;
    let query_name = user.name;
    
    let obj:Tpl_rankInfo = {
        list: list,
        rank_name:rank_typeName[rank_type[call.req.type]],
        query_rank: query_rank,
        query_name: query_name
    }
    user.sendMsg(call.req.template,obj)
}